package com.cya.forumproject.common;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

/**
 * @author ：陈奕安（3048279304@qq.com）
 * @date ：Created in 2025/9/19 19:39
 * @description：
 * @modified By：
 * @version:
 */
//同意返回结果
@Data
public class AppResult<T> {
    @JsonInclude(JsonInclude.Include.ALWAYS)//无论任何情况都参加json序列化
    private int code;
    @JsonInclude(JsonInclude.Include.ALWAYS)//无论任何情况都参加json序列化

    private String message;
    @JsonInclude(JsonInclude.Include.ALWAYS)//无论任何情况都参加json序列化

    private T data;
    public AppResult(int code, String message) {
    this(code,message,null);

    }

    public AppResult(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static AppResult success(){
        return new AppResult(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage());
    }
    public static AppResult success(String message){
        return new AppResult(ResultCode.SUCCESS.getCode(), message);
    }

    public static <T> AppResult<T> success(T data){
        return new AppResult<>(ResultCode.SUCCESS.getCode(),ResultCode.SUCCESS.getMessage(),data);
    }

    public static <T> AppResult<T> success(String message,T data){
        return new AppResult<>(ResultCode.SUCCESS.getCode(), message,data);
    }
    public static AppResult failed() {
        return new AppResult(ResultCode.FAILED.getCode(), ResultCode.FAILED.getMessage());
    }
    public static AppResult failed(String message){
        return new AppResult(ResultCode.FAILED.getCode(),message);

    }
    public static AppResult failed(ResultCode resultCode){
        return new AppResult(resultCode.getCode(),resultCode.getMessage());
    }
}